package com.day14;

public class StudentTest {

    public static void main(String[] args) {
        Student student = new Student();
        try {
            student.regist(-100);
        } catch (Exception e) {
//            e.printStackTrace();
            System.out.println(e.getMessage());
        }
        System.out.println(student);
    }
}


class Student {

    private int id;

    public void regist(int id) throws Exception {
        if(id > 0){
            this.id = id;
        }else {
//            System.out.println("您输入的数据非法!");
            //运行时异常编译通过，运行时可能会报错
//            throw new RuntimeException("您输入的数据非法");
//            throw new Exception("您输入的数据非法");
            throw new MyException("不能输入负数");
        }
    }

    @Override
    public String toString() {
        return super.toString();
    }
}